﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QLNHang.BUS;
using QLNHang.DTO;

namespace QLNHang.GUI
{
    public partial class ucLapThucDon : UserControl
    {
        private int maThucDon; 
        public ucLapThucDon()
        {
            InitializeComponent();
        }

        private void ucLapThucDon_Load(object sender, EventArgs e)
        {
            ThucDonBUS td = new ThucDonBUS();
            maThucDon = td.TaoThucDon();
            txtMaThucDon.Text = maThucDon.ToString();
            LayMonAn();
        }

        private void btnLapThucDon_Click(object sender, EventArgs e)
        {
            ThucDonBUS td = new ThucDonBUS();
            td.CapNhatThucDon(maThucDon, dtpNgayApDung.Value);
        }

        private void btnThemMon_Click(object sender, EventArgs e)
        {
            DataGridViewRow row = (DataGridViewRow)dgvDanhSachMonAn.Rows[0].Clone();
            row.Cells[0].Value = dgvDanhSachMonAn.RowCount.ToString();
            row.Cells[1].Value = cbDanhSachMonAn.Text.ToString();
            row.Cells[2].Value = txtSoLuong.Text;
            dgvDanhSachMonAn.Rows.Add(row);
            ChiTietThucDonDTO cttdDto = new ChiTietThucDonDTO();
            cttdDto.MaThucDon = int.Parse(txtMaThucDon.Text);
            cttdDto.MaMonAn = int.Parse(cbDanhSachMonAn.SelectedValue.ToString());
            cttdDto.SoKhauPhan = int.Parse(txtSoLuong.Text);
            ChiTietThucDonBUS cttdBus = new ChiTietThucDonBUS();
            cttdBus.ThemChiTietThucDon(cttdDto);
        }

        private void LayMonAn()
        {
            MonAnBUS ma = new MonAnBUS();
            DataTable dt = ma.LayMonAn();
            cbDanhSachMonAn.DataSource = dt;
            cbDanhSachMonAn.DisplayMember = "TenMonAn";
            cbDanhSachMonAn.ValueMember = "MaMonAn";
        }
    }
}
